]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensionSystem: Add methods to enable/disable extensions
authorDidier Roche <didrocks@ubuntu.com>
Wed, 17 Jan 2018 12:43:11 +0000 (13:43 +0100)
committerFlorian Müllner <florian.muellner@gmail.com>
Sat, 20 Jul 2019 14:17:35 +0000 (14:17 +0000)
Extensions are currently enabled or disabled by directly changing the
list in the 'enabled-extensions' GSettings key. As we will soon add
an overriding 'disabled-extensions' key as well, it makes sense to
offer explicit API for enabling/disabling to avoid duplicating the
logic.

For the corresponding D-Bus API, the methods were even mentioned in
the GSettings schema, albeit unimplemented until now.

https://bugzilla.gnome.org/show_bug.cgi?id=789852

data/dbus-interfaces/org.gnome.Shell.Extensions.xml
js/ui/extensionDownloader.js
js/ui/extensionSystem.js
js/ui/shellDBus.js

index 34a65af44c9185ee0d90dbac740fd1b062140f72..309a9f20720a03cba076332b6920776ac24d986e 100644 (file)
       <arg type="s" direction="in" name="uuid"/>
     </method>
 
+    <!--
+        EnableExtension:
+        @uuid: The UUID of the extension
+        @success: Whether the operation was successful
+
+        Enable an extension.
+    -->
+    <method name="EnableExtension"> \
+      <arg type="s" direction="in" name="uuid"/> \
+      <arg type="b" direction="out" name="success"/> \
+    </method> \
+
+    <!--
+        DisableExtension:
+        @uuid: The UUID of the extension
+        @success: Whether the operation was successful
+
+        Disable an extension.
+    -->
+    <method name="DisableExtension"> \
+      <arg type="s" direction="in" name="uuid"/> \
+      <arg type="b" direction="out" name="success"/> \
+    </method> \
+
     <!--
         LaunchExtensionPrefs:
         @uuid: The UUID of the extension
index 25027a3aaaf31c0c791d2a2959f09f43b54fee03..aa5d7b94dc60326e581408c2976e7815d55055c5 100644 (file)
@@ -5,7 +5,6 @@ const { Clutter, Gio, GLib, GObject, Soup } = imports.gi;
 const Config = imports.misc.config;
 const Dialog = imports.ui.dialog;
 const ExtensionUtils = imports.misc.extensionUtils;
-const ExtensionSystem = imports.ui.extensionSystem;
 const FileUtils = imports.misc.fileUtils;
 const Main = imports.ui.main;
 const ModalDialog = imports.ui.modalDialog;
@@ -225,16 +224,11 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
         }
 
         function callback() {
-            // Add extension to 'enabled-extensions' for the user, always...
-            let enabledExtensions = global.settings.get_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY);
-            if (!enabledExtensions.includes(uuid)) {
-                enabledExtensions.push(uuid);
-                global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions);
-            }
-
             try {
                 let extension = ExtensionUtils.createExtensionObject(uuid, dir, ExtensionUtils.ExtensionType.PER_USER);
                 Main.extensionManager.loadExtension(extension);
+                if (!Main.extensionManager.enableExtension(uuid))
+                    throw new Error(`Cannot add ${uuid} to enabled extensions gsettings key`);
             } catch (e) {
                 uninstallExtension(uuid);
                 errback('LoadExtensionError', e);
index a16aa22f0ddb9a0e3b5f6cf36330f0f9ad036352..0b22783cc84e2bd233a7a613e1798fc91b25c1fa 100644 (file)
@@ -126,6 +126,32 @@ var ExtensionManager = class {
         }
     }
 
+    enableExtension(uuid) {
+        if (!ExtensionUtils.extensions[uuid])
+            return false;
+
+        let enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY);
+        if (!enabledExtensions.includes(uuid)) {
+            enabledExtensions.push(uuid);
+            global.settings.set_strv(ENABLED_EXTENSIONS_KEY, enabledExtensions);
+        }
+
+        return true;
+    }
+
+    disableExtension(uuid) {
+        if (!ExtensionUtils.extensions[uuid])
+            return false;
+
+        let enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY);
+        if (enabledExtensions.includes(uuid)) {
+            enabledExtensions = enabledExtensions.filter(item => item !== uuid);
+            global.settings.set_strv(ENABLED_EXTENSIONS_KEY, enabledExtensions);
+        }
+
+        return true;
+    }
+
     logExtensionError(uuid, error) {
         let extension = ExtensionUtils.extensions[uuid];
         if (!extension)
index 7976eeaae360007e9741d2f58da8e8d70299b8d2..fad3cf0a2666c8aef8ecc9b94005f1319198e4b9 100644 (file)
@@ -320,6 +320,14 @@ var GnomeShellExtensions = class {
         return ExtensionDownloader.uninstallExtension(uuid);
     }
 
+    EnableExtension(uuid) {
+        return Main.extensionManager.enableExtension(uuid);
+    }
+
+    DisableExtension(uuid) {
+        return Main.extensionManager.disableExtension(uuid);
+    }
+
     LaunchExtensionPrefs(uuid) {
         let appSys = Shell.AppSystem.get_default();
         let app = appSys.lookup_app('gnome-shell-extension-prefs.desktop');